//************************
// Example for Fragment  *
//************************
package com.ahha.example.rssreader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class RssfeedActivity extends Activity implements MyListFragment.OnItemSelectedListener{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rssfeed);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.mainmenu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch(item.getItemId()){
		case R.id.action_refresh:
			Toast.makeText(this, "Action refersh selected", Toast.LENGTH_SHORT).show();
			break;
		case R.id.action_setting:
			Toast.makeText(this, "Action setting seleted", Toast.LENGTH_LONG).show();
			break;
		default:
			break;
		}
		
		return true;
	}

	@Override
	public void onRssItemSelected(String link) {
		// TODO Auto-generated method stub
		DetailFragment fragment = (DetailFragment) getFragmentManager().findFragmentById(R.id.detailFragment);
		if(fragment != null && fragment.isInLayout()){
			fragment.setText(link);
		}else{
			Log.v("new activity", "33333333333");
			Intent intent = new Intent(getApplicationContext(), DetailActivity.class);
			intent.putExtra(DetailActivity.EXTRA_URL, link);
			startActivity(intent);
		}
	}

	

}
